package com.softline.documentsmall.controller;

import com.alibaba.fastjson.JSONObject;
import com.softline.documentsmall.entity.DictionaryInfoVO;
import com.softline.documentsmall.entity.ParamVo;
import com.softline.documentsmall.entity.WordVo;
import com.softline.documentsmall.ret.ReturnVO;
import com.softline.documentsmall.ret.ReturnVOUtils;
import com.softline.documentsmall.service.DictionaryRelationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liusheng
 */
@Api(value="术语关联相关接口",tags={"术语关联相关接口"})
@RestController
@RequestMapping("/dictionary/relation")
@CrossOrigin(allowCredentials = "true",allowedHeaders = "*")
public class DictionaryRelationController {

    @Autowired
    DictionaryRelationService dictionaryRelationService;

    @ApiOperation(value="展示术语列表", notes = "展示术语列表")
    @GetMapping(value = "/list")
    public ReturnVO insert(@RequestParam(name = "type", defaultValue = "cn") String type,
                           @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                           @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                           @RequestParam(name = "title", defaultValue = "") String title){
        JSONObject json = dictionaryRelationService.list(type,pageNum,pageSize,title);
        return ReturnVOUtils.success(json);
    }

    @ApiOperation(value="修改术语关键词", notes = "修改术语关键词")
    @PostMapping(value = "/edit")
    public ReturnVO edit(@RequestBody ParamVo paramVo){
        JSONObject json = dictionaryRelationService.edit(paramVo.getWordList(),paramVo.getDictionaryId());
        return ReturnVOUtils.success(json);
    }

    @ApiOperation(value="编辑列表", notes = "编辑列表")
    @GetMapping(value = "/editList")
    public ReturnVO editList(@RequestParam(name = "dictionaryId") String dictionaryId){
        JSONObject json = dictionaryRelationService.editList(dictionaryId);
        return ReturnVOUtils.success(json);
    }
}
